package com.ckzp.jfinal.weixin.impl;

import com.ckzp.core.util.DateUtil;
import com.ckzp.jfinal.weixin.model.WxMember;
import com.ckzp.weixin.service.MessageAction;
import com.ckzp.weixin.service.ServiceRequest;
import com.ckzp.weixin.service.ServiceResponse;
import com.ckzp.weixin.service.response.TextResponse;

import java.util.Date;

/**
 * 取消关注公众号
 * Created by 51594 on 2023/4/3.
 */
public class EventUnSubscribeAction implements MessageAction {
    /**
     * @param request
     * @return
     */
    public ServiceResponse doAction(ServiceRequest request) {
        if (request != null) {
            String wx_openid = request.getFromUserName();
            WxMember member = WxMember.dao.findFirst("select * from wx_member where wx_openid=?", wx_openid);
            if (member != null) {
                Date sub_date = new Date();
                int dateint = DateUtil.getYYYYMMDD(sub_date);
                member.set("sub_tag", 0).set("sub_date", sub_date).set("sub_dateint", dateint).update();
                //Record record = new Record().set("")
            }
            TextResponse response = TextResponse.init(request);
            response.setContent("");
            return response;
        }
        return null;
    }
}